#include "transitionbutton.h"
#include <QStyleOptionGraphicsItem>
#include <QPainter>
#include "mainwindow.h"
#include "giftpixmap.h"

extern AnimationView* getAnimationView() ;

void Button::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
{
	bool down = option->state & QStyle::State_Sunken;
	QRectF r = boundingRect();

	QLinearGradient grad(r.topLeft(), r.bottomRight());
	grad.setColorAt(down ? 1 : 0, option->state & QStyle::State_MouseOver ? Qt::white : Qt::lightGray);
	grad.setColorAt(down ? 0 : 1, Qt::darkGray);
	painter->setPen(Qt::darkGray);
	painter->setBrush(grad);
	painter->drawEllipse(r);

	QLinearGradient grad2(r.topLeft(), r.bottomRight());
	grad.setColorAt(down ? 1 : 0, Qt::darkGray);
	grad.setColorAt(down ? 0 : 1, Qt::lightGray);
	painter->setPen(Qt::NoPen);
	painter->setBrush(grad);

	if (down)
		painter->translate(2, 2);

	painter->drawEllipse(r.adjusted(5, 5, -5, -5));
	painter->drawPixmap(r.center( ).x() - pixmap.width() / 2, r.center( ).y() - pixmap.height() / 2, pixmap);
}

void Button::show()
{
	((getAnimationView()->getItems()).at(0))->setOpacity(1.0);
}